package com.member.web.controller.shop;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.member.common.annotation.Log;
import com.member.common.core.controller.BaseController;
import com.member.common.core.domain.AjaxResult;
import com.member.common.core.page.TableDataInfo;
import com.member.common.enums.BusinessType;
import com.member.common.utils.poi.ExcelUtil;
import com.member.shop.domain.SysBizSeckillGoodsPage;
import com.member.shop.service.ISysBizSeckillGoodsPageService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 【秒杀页关联商品】控制器
 *
 * @author lixinchen
 * @version 1.0
 * @date 2025-04-12
 **/
@RestController
@RequestMapping("/shop/seckillGoods")
public class SysBizSeckillGoodsPageController extends BaseController {
    @Resource
    private ISysBizSeckillGoodsPageService sysBizSeckillGoodsPageService;

    /**
     * 查询秒杀页关联商品列表
     */
    @PreAuthorize("@ss.hasPermi('shop:seckillGoods:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysBizSeckillGoodsPage sysBizSeckillGoodsPage) {
        startPage();
        LambdaQueryWrapper<SysBizSeckillGoodsPage> queryWrapper = new LambdaQueryWrapper<SysBizSeckillGoodsPage>();
        List<SysBizSeckillGoodsPage> list = sysBizSeckillGoodsPageService.selectSysBizSeckillGoodsPageList(queryWrapper);
        return getDataTable(list);
    }

    /**
     * 导出秒杀页关联商品列表
     */
    @PreAuthorize("@ss.hasPermi('shop:seckillGoods:export')")
    @Log(title = "秒杀页关联商品", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysBizSeckillGoodsPage sysBizSeckillGoodsPage) {
        LambdaQueryWrapper<SysBizSeckillGoodsPage> queryWrapper = new LambdaQueryWrapper<SysBizSeckillGoodsPage>();
        List<SysBizSeckillGoodsPage> list = sysBizSeckillGoodsPageService.selectSysBizSeckillGoodsPageList(queryWrapper);
        ExcelUtil<SysBizSeckillGoodsPage> util = new ExcelUtil<SysBizSeckillGoodsPage>(SysBizSeckillGoodsPage.class);
        util.exportExcel(response, list, "秒杀页关联商品数据");
    }

    /**
     * 获取秒杀页关联商品详细信息
     */
    @PreAuthorize("@ss.hasPermi('shop:seckillGoods:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(sysBizSeckillGoodsPageService.selectSysBizSeckillGoodsPageById(id));
    }

    /**
     * 新增秒杀页关联商品
     */
    @PreAuthorize("@ss.hasPermi('shop:seckillGoods:add')")
    @Log(title = "秒杀页关联商品", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysBizSeckillGoodsPage sysBizSeckillGoodsPage) {
        return toAjax(sysBizSeckillGoodsPageService.insertSysBizSeckillGoodsPage(sysBizSeckillGoodsPage));
    }

    /**
     * 修改秒杀页关联商品
     */
    @PreAuthorize("@ss.hasPermi('shop:seckillGoods:edit')")
    @Log(title = "秒杀页关联商品", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysBizSeckillGoodsPage sysBizSeckillGoodsPage) {
        return toAjax(sysBizSeckillGoodsPageService.updateSysBizSeckillGoodsPage(sysBizSeckillGoodsPage));
    }

    /**
     * 删除秒杀页关联商品
     */
    @PreAuthorize("@ss.hasPermi('shop:seckillGoods:remove')")
    @Log(title = "秒杀页关联商品", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(sysBizSeckillGoodsPageService.deleteSysBizSeckillGoodsPageByIds(ids));
    }
}
